home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / net / parnet-3.2 / extras / parpc / amigafiles / test / listen.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  87 lines

  1. /*
  2.  *  LISTEN.C
  3.  *
  4.  *  LISTEN port
  5.  *
  6.  *  receives data from port and prints results.
  7.  */
  8.  
  9. #include "defs.h"
  10. #include <exec/types.h>
  11. #include <exec/io.h>
  12. #include <exec/ports.h>
  13. #include <libraries/dos.h>
  14. #include <devices/parnet.h>
  15.  
  16. typedef struct IORequest IOR;
  17.  
  18. IOParReq iob[2];
  19.  
  20. extern PORT *CreatePort();
  21.  
  22. int
  23. brk(void)
  24. {
  25.     return(0);
  26. }
  27.  
  28. void
  29. main(ac, av)
  30. int ac;
  31. char *av[];
  32. {
  33.     PORT *port = CreatePort(NULL, 0);
  34.     char buf1[16];
  35.     char buf2[16];
  36.  
  37.     onbreak(brk);
  38.     iob[0].io_Message.mn_ReplyPort = port;
  39.     iob[0].io_Port = atoi(av[1]);
  40.     iob[0].io_Flags= PRO_DGRAM;
  41.  
  42.     if (OpenDevice("parnet.device", 0, (IOR *)&iob[0], 0)) {
  43.     printf("Unable to open parnet.device, error %d %d\n", iob[0].io_Error, iob[0].io_Actual);
  44.     exit(1);
  45.     }
  46.     printf("Device $%08lx Unit $%08lx\n", iob[0].io_Device, iob[0].io_Unit);
  47.  
  48.     iob[0].io_Command = CMD_READ;
  49.     iob[0].io_Data    = (APTR)buf1;
  50.     iob[0].io_Length  = sizeof(buf1);
  51.  
  52.     iob[1] = iob[0];
  53.     iob[1].io_Data    = (APTR)buf2;
  54.  
  55.     SendIO((IOR *)&iob[0]);
  56.     SendIO((IOR *)&iob[1]);
  57.  
  58.     for (;;) {
  59.     long mask;
  60.     IOParReq *io;
  61.  
  62.     mask = Wait(SIGBREAKF_CTRL_E | (1 << port->mp_SigBit));
  63.  
  64.     if (mask & SIGBREAKF_CTRL_E)
  65.         break;
  66.  
  67.     while (io = (IOParReq *)GetMsg(port)) {
  68.         if (io->io_Actual < 0)
  69.         printf("READ %d\n", io->io_Actual);
  70.         else {
  71.         ((char *)io->io_Data)[io->io_Actual] = 0;
  72.         printf("READ %d %s\n", io->io_Actual, io->io_Data);
  73.         }
  74.         SendIO((IOR *)io);
  75.     }
  76.     }
  77.     printf("Aborting...\n");
  78.     AbortIO((IOR *)&iob[0]);
  79.     AbortIO((IOR *)&iob[1]);
  80.     WaitIO((IOR *)&iob[0]);
  81.     WaitIO((IOR *)&iob[1]);
  82.     printf("Closing...\n");
  83.     CloseDevice((IOR *)&iob[0]);
  84.     DeletePort(port);
  85. }
  86.  
  87.